﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FFSupplier.Common.CustomException;

namespace FFSupplier.Common.Configuration
{
    public class ConnectionStringsConfiguration : IConfiguration
    {
        public string GetConfigurationData(string keyName)
        {
            string result;
            try
            {
                result = ConfigurationManager.ConnectionStrings[keyName].ConnectionString;
            }
            catch (Exception e)
            {
                throw new MissingConfigurationDataException(string.Format("missing configuration {0}. ", keyName) + e.Message);
            }
            if (string.IsNullOrEmpty(result))
            {
                throw new ErrorConfigurationDataException(string.Format("can't find {0} from config", result));
            }
            return result;
        }
    }
}
